<template>
  <div class="app-container" v-loading="tableLoading" element-loading-text="模型加载中...">
    <template v-if="dataSet.setSearchTableData && dataSet.setSearchTableData.length">
      <search :setSearchTableData="dataSet.setSearchTableData" @throwSearchData="searchList"
              @clearSearchData="clearSearch"></search>
    </template>

    <TableColumn :yuanSetTableData="dataSet.yuanSetTableData" :rightTableSetting="dataSet.rightTableSetting" :tableOptions="tableOptions"
                 ref="refTableColumn"></TableColumn>
  </div>
</template>

<script>
import search from "@/lowcode/components/search";
import TableColumn from "@/lowcode/components/TableColumn";
import {getList,viewTable} from "@/api/public";
import {listMenu} from "@/api/system/menu";
export default {
  name: "index",
  components:{
    search,
    TableColumn
  },
  data(){
    return {
      dataSet:{},
      tableLoading:false,
      tableOptions:{
        addUrl:'/common/online/add',
        editUrl:'/common/online/edit',
        listUrl:'/common/online/page',
        delUrl:'/common/online/del'
      },
    }
  },
  created() {
    this.tableLoading = true
    listMenu().then(res => {
      if(res.data && res.data.length){
        const ind = res.data.findIndex(item => {
          return item.menuName == this.$route.meta.title
        })
        const strChar = res.data[ind].path
        this.tableOptions.tableName = strChar
        //获取列表配置
        getList({tableName:strChar}).then(res => {
          if(res.data.records && res.data.records.length){
            viewTable(res.data.records[0].id).then(result => {
              if(result.code == 200){
                this.dataSet = JSON.parse(result.data.tableSettingJson)
                console.log(this.dataSet,'this.dataSet')
              }
              else{
                this.dataSet = {}
              }
              this.tableLoading = false
            })
          }
        }).catch(()=>{
          this.dataSet = {}
          this.tableLoading = false
        })
      }
    })

  },
  methods:{
    searchList(value){
      this.$refs.refTableColumn.getSearchData(value)
    },
    clearSearch(){
      this.$refs.refTableColumn.clearSearchData()
    }
  }
}
</script>

<style scoped lang="scss">

</style>
